package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.MallMember;
import com.sc.nft.entity.MallMemberEquityTemplate;
import com.sc.nft.entity.dto.AdminMemberEquityTemplatePageDTO;
import com.sc.nft.mapper.MallMemberEquityTemplateMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.dao
 * @Project：sc_metago
 * @name：MallMemberEquityTemplateDao
 * @Date：2024/4/2 19:29
 * @Filename：MallMemberEquityTemplateDao
 */
@Slf4j
@Repository
public class MallMemberEquityTemplateDao extends ServiceImpl<MallMemberEquityTemplateMapper, MallMemberEquityTemplate> {

    /**
     * 获取商城会员权益模版列表(管理后台)
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    public Page<AdminMemberEquityTemplatePageDTO> getAdminMemberEquityTemplatePageDTO(Integer pageNo, Integer pageSize, Boolean status) {
        return baseMapper.getAdminMemberEquityTemplatePageDTO(new Page(pageNo, pageSize), status);
    }

    /**
     * 获取所有已使用的权益模版
     *
     * @return
     */
    public List<MallMemberEquityTemplate> templatesAlreadyUsed() {
        return baseMapper.templatesAlreadyUsed();
    }

    /**
     * 修改商城会员权益模版状态
     *
     * @param id
     * @param status
     * @return
     */
    public boolean updateStatus(Long id, Boolean status) {
        UpdateWrapper<MallMemberEquityTemplate> wrapper = new UpdateWrapper<>();
        wrapper.eq("id", id);
        wrapper.set("status", status);
        return update(new MallMemberEquityTemplate(), wrapper);
    }

    public List<MallMemberEquityTemplate> getByIdList(List<Long> idList) {
        LambdaQueryWrapper<MallMemberEquityTemplate> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(MallMemberEquityTemplate::getId,idList);
        return list(wrapper);
    }
}
